package day13.Collectionzuoye;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class TaskOne {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<String> list = new ArrayList<>();
        String first = sc.nextLine();
        String[] split = first.split("-");
        int count = Integer.parseInt(split[0]);
        for (int i = 0; i < count; i++) {
            list.add(sc.next());
        }
        List<String> list1 = firstLine(list, split[1]);
        System.out.println(list1);
        List<String> list2 = secondLine(list1, split[2]);
        System.out.println(list2);
        list2.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                String s = (o1.split("-"))[2];
                String s1 = (o2.split("-"))[2];
               return Integer.parseInt(s1)-Integer.parseInt(s);

            }
        });
        System.out.println(list2);
    }

    public static List<String> firstLine(List<String> list, String x) {
        List<String> list1 = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            String[] split = list.get(i).split("-");
            if (x.equals(split[0])) {
                list1.add(list.get(i));
            }
        }
        return list1;
    }
    public static List<String> secondLine(List<String> list, String y) {
        List<String> list1 = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            String[] split = list.get(i).split("-");
            if (y.equalsIgnoreCase(split[1])) {
                list1.add(list.get(i));
            }
        }
        return list1;
    }
}
